package com.huadragon.marathonweb.controller.front.login;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.qq.connect.QQConnectException;
import com.qq.connect.oauth.Oauth;




@Controller
@RequestMapping("/login")
public class LoginController  {

    /*@Autowired
	private ILoginService loginService;*/
	
	@Autowired
	private Oauth qqOauth;
	
	@Autowired
	private  HttpServletRequest request;
	
	@Autowired
	private  HttpServletResponse response;
	
    /**
	 * 转到登陆页面
	 * @return
	 */
    @RequestMapping(value = "/index")
	public String index() {
    	//此处可以检测是否登陆，若登陆直接跳转到主页，未登陆则在登陆页面。
    	/*if (LoginUserHolder.getLoginAccount() != null) {
			return "redirect:/";
		}*/
    	return "/front/login/index";
    	//也可以不检测是否登陆，不管登陆与否，都可以显示此页面，让用户再次登陆。
		//return "/manage/account/login";
	}
    
    @RequestMapping(value = "/oauth2/sina")
	public String oauth2Sina()  {
    	response.setContentType("text/html;charset=utf-8");
        try {
        	return "redirect:"+qqOauth.getAuthorizeURL(request);
        } catch (QQConnectException e) {
            e.printStackTrace();
        }
        return "";
    }
    
    @RequestMapping(value = "/oauth2/qq")
	public String oauth2Qq() {
    	response.setContentType("text/html;charset=utf-8");
        try {
        	return "redirect:"+qqOauth.getAuthorizeURL(request);
        } catch (QQConnectException e) {
            e.printStackTrace();
        }
        return "";
	}
    
    
    
}
